<template>
	<view class="page">
		<view class="page_con">
			<uni-nav-bar color="#999" background-color="transparent" status-bar left-icon="left" :border="false"
				title="" @clickLeft="back" />
			<view class="slogen_item">
				<image src="@/static/img/login/login_slogen.png" mode="aspectFit"></image>
			</view>
			<view class="list_section">
				<view class="list_con">
					<view class="list_title">
						序号集章
					</view>
					<view class="lits_item">
						<input class="" placeholder="请输入集章序号" type="text" v-model="badgeCode">
					</view>
					<view class="butt_submit">
						<view class="but" v-if="badgeCode && badgeCode.length > 5" @click="submit">
							立即领取
						</view>
						<view class="but but1" v-else>
							立即领取
						</view>
					</view>
				</view>
			</view>
			<view class="activity_desc" @click="openWeb('/pages/home/activityDesc?type=5')">
				活<br>动<br>说<br>明
			</view>

			<!-- 成功 -->
			<uni-popup ref="popup1" background-color="transparent">
				<view class="popup-content1">
					<image class="img2" src="@/static/img/index/popup_image1.png" mode=""></image><br>
					<image class="img1" src="@/static/img/index/popup_image3.png" mode=""></image>
					<view class="butt_submit">
						<image src="@/static/img/exchange/close.png" mode="" @click="closePopup1"></image>
					</view>
				</view>
			</uni-popup>
			<!-- 失败 -->
			<uni-popup ref="popup2" background-color="transparent">
				<view class="popup-content2">
					<image class="img2" src="@/static/img/index/popup_image2.png" mode=""></image><br>
					<view class="resCode">
						{{msg}}
					</view>
					<view class="butt_submit">
						<image src="@/static/img/exchange/close.png" mode="" @click="closePopup2"></image>
					</view>
				</view>
			</uni-popup>
		</view>
		<!-- 底部tabBar -->
		<tabbar current="4"></tabbar>
	</view>
</template>

<script>
	import {
		setBadgeExchangeByCode
	} from '@/api/api.js'
	import tabbar from '@/components/tabBar.vue' //自定义tabBar
	export default {
		data() {
			return {
				badgeCode: '', //兑换码
				msg: '领取失败'
			}
		},
		components: {
			tabbar,
		},
		onLoad(e) {

		},
		onShow() {},
		onHide() {},
		methods: {
			back() {
				const pages = getCurrentPages(); // 获取当前页面栈
				if (pages.length < 2) {
					uni.redirectTo({
						url: '/pages/home/index'
					})
				}else{
					uni.navigateBack()
				}
			},
			closePopup2() {
				this.$refs.popup2.close()
			},
			closePopup1() {
				this.badgeCode = ''
				this.$refs.popup1.close()
			},
			submit() {
				if (!this.badgeCode) {
					uni.showToast({
						icon: 'none',
						title: "请输入兑换码序列号哦~"
					})
					return
				}
				if (this.badgeCode.length !== 6) {
					uni.showToast({
						icon: 'none',
						title: "请输入正确的序列码哦~"
					})
					return
				}
				setBadgeExchangeByCode({
					'badgeCode': this.badgeCode
				}).then(res => {
					// console.log(res)
					if (res.code === 0) {
						this.$refs.popup1.open("center")
					} else {
						this.msg = res.msg
						this.$refs.popup2.open("center")
					}
				})
			},
			openWeb(v) {
				uni.navigateTo({
					url: v
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {}

	.page_con {
		height: 100vh;
		height: 100dvh;
		background-image: url('@/static/img/index/index_bakc.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
		background-position: top center;
		position: relative;
		overflow: hidden;

		.slogen_item {
			text-align: center;

			image {
				margin-top: 12%;
				width: 619rpx;
				height: 260rpx;
			}
		}

		.num_section {
			margin-top: 40rpx;
			text-align: center;
			font-size: 28rpx;
			color: #1F6DC1;
			height: 60rpx;
			line-height: 60rpx;
			background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, .8), rgba(255, 255, 255, 0));

			text {
				border-radius: 50%;
				text-align: center;
				color: #fff;
				height: 48rpx;
				line-height: 48rpx;
				width: 48rpx;
				background-color: #1F6DC1;
				margin: 0 12rpx;
				display: inline-block;

			}
		}

		.activity_desc {
			position: absolute;
			right: 0;
			top: 130rpx;
			background: #26292C;
			border-radius: 8rpx 0rpx 0rpx 8rpx;
			opacity: 0.61;
			font-size: 28rpx;
			color: #FFFFFF;
			padding: 12rpx;
		}

		.list_section {
			margin-top: 40rpx;

			.list_con {
				background: #FFFAF1;
				border-radius: 32rpx;
				padding: 0 40rpx 40rpx;
				position: relative;
				min-height: 1200rpx;

				.active1 {
					width: 109rpx;
					height: 109rpx;
					position: absolute;
					left: 0;
					top: 0;
				}

				.list_title {
					width: 365rpx;
					height: 75rpx;
					line-height: 75rpx;
					background: linear-gradient(90deg, #EDD08A, #BD8229);
					border-radius: 0rpx 0rpx 32rpx 32rpx;
					font-size: 32rpx;
					color: #FFFFFF;
					margin: 0 auto;
					text-align: center;
				}

				.min_title {
					font-size: 28rpx;
					color: #000000;
					text-align: center;
					margin-top: 100rpx;
				}

				.lits_item {
					display: flex;
					justify-content: center;
					align-items: center;
					flex-wrap: wrap;
					margin: 100rpx 0 70rpx;

					.but_minus {
						background: #F5F5F5;
						border-radius: 8rpx;
						border: 1px solid #E8E8E8;
						width: 90rpx;
						height: 65rpx;
						font-size: 40rpx;
						color: #777777;
					}

					input {
						background: #FFFFFF;
						border-radius: 8rpx;
						border: 1px solid #E8E8E8;
						width: 565rpx;
						height: 68rpx;
						padding: 0 20rpx;
					}

					.but_add {
						width: 90rpx;
						height: 65rpx;
						background: #F5F5F5;
						border-radius: 8rpx;
						border: 1px solid #E8E8E8;
						font-size: 40rpx;
						color: #777777;
					}

				}

				.page_pagination {
					width: 80%;
					margin: 0 auto;
				}


			}
		}

		.butt_submit {
			text-align: center;
			margin-top: 50rpx;

			.but {
				margin: 0 auto;
				width: 350rpx;
				height: 129rpx;
				background-image: url("@/static/img/exchange/butt_back.png");
				font-size: 32rpx;
				background-size: 100% 100%;
				background-repeat: no-repeat;
				background-position: center;
				color: #FFFFFF;
				text-align: center;
				padding-top: 30rpx;
				font-weight: bold;

			}

			.but1 {
				background-image: url("@/static/img/index/butt_back_disabled.png");

			}
		}

		.banner {
			margin-top: 40rpx;
			text-align: center;

			image {
				width: 702rpx;
				height: 275rpx;
			}
		}

		.popup-content1 {
			text-align: center;

			.img1 {
				width: 220rpx;
				height: 80rpx;
				margin: 66rpx 0 0;
			}

			.img2 {
				width: 358rpx;
				height: 358rpx;
			}

			.butt_submit {
				image {
					width: 65rpx;
					height: 65rpx;
				}
			}
		}

		.popup-content2 {
			text-align: center;

			.img1 {
				width: 220rpx;
				height: 80rpx;
				margin: 66rpx 0 0;
			}

			.img2 {
				width: 288rpx;
				height: 288rpx;
			}

			.resCode {
				color: #fff;
				font-weight: bold;
				margin-top: 40rpx;
			}

			.butt_submit {
				image {
					width: 65rpx;
					height: 65rpx;
				}
			}
		}
	}
</style>
